require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsQuickBattleHandler ={};
local this = RedDotsQuickBattleHandler;

local sweepConfig = nil;

function RedDotsQuickBattleHandler.init()
    CloseEvent(Config.EventType.QuickBattle, this.update);
    ListenEvent(Config.EventType.QuickBattle, this.update);
    CloseEvent(Config.EventType.Fresh_NewStage, this.update);
    ListenEvent(Config.EventType.Fresh_NewStage, this.update);
    if sweepConfig==nil then
        sweepConfig = G.dataTable["t_sweep"];
    end

    return this;
end

---快速战斗是否免费
function RedDotsQuickBattleHandler.getFlag()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.QuickBattle, false) then
        local time = logicMgr.HeroManager.getQuickTimes();
        local singleConfig = sweepConfig[tostring(time + 1)];
        if singleConfig.f_SweepCost == 0 then
            return Config.RedDotsFlagState.Needful;
        end
    end
    return Config.RedDotsFlagState.None;
end

function RedDotsQuickBattleHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.FreeFastBattle);
end